/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-04-12
 * Time:17:57
 */

/**
 * BM15 删除有序链表中重复的元素-l
 */

public class deleteDuplicates {
    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null){
            return head;
        }
        // write code here
        ListNode slow = head;
        ListNode fast = head.next;
        while (fast != null) {
            if (fast.val == slow.val) {
                slow.next = fast.next;
            } else {
                slow = fast;
            }
            fast = fast.next;
        }
        return head;
    }

}
